package com.htu.hdfs;
import java.io.IOException;  
import java.net.URI;  
import org.apache.hadoop.conf.Configuration;  
import org.apache.hadoop.fs.FSDataOutputStream;  
import org.apache.hadoop.fs.FileSystem;  
import org.apache.hadoop.fs.Path;  
public class WriteFile {
	 public static void main(String[] args) throws IOException {  
	        Configuration conf = new Configuration();  
	  
	        String hdfsPath = "hdfs://localhost:9000";  
	        FileSystem hdfs = FileSystem.get(URI.create(hdfsPath), conf);  
	  
	        String filePath = "/hdfstest/writefile";  
	  
	        FSDataOutputStream create = hdfs.create(new Path(filePath));  
	  
	        System.out.println("Step 1 Finish!");  
	  
	        String sayHi = "hello world hello data!";  
	        byte[] buff = sayHi.getBytes();  
	        create.write(buff, 0, buff.length);  
	        create.close();  
	        System.out.println("Step 2 Finish!");  
	    }  
}
